package com.yunxun.controller;

import com.google.gson.Gson;
import com.rabbitmq.client.Channel;
import com.yunxun.amqp.RPCServer;
import com.yunxun.consist.EntityConsist;
import com.yunxun.entity.MessageEntity;
import com.yunxun.service.MessageService;
import com.yunxun.utils.ChannelUtil;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;

import java.util.List;

@Controller
public class MessageController {
    @Autowired
    private MessageService messageService;
        @RequestMapping("/")
        @ResponseBody
        public String collectorMessage(){
            String url = "https://www.cnbeta.com/";
            String encoding ="utf-8";

               int flag = messageService.insert(url,encoding, EntityConsist.MessageConsist.HOME_PAGE);
                url = "https://www.cnbeta.com/category/movie.htm";
                flag = 0;
                flag = messageService.insert(url,encoding,EntityConsist.MessageConsist.MOVIE);
                url = "https://www.cnbeta.com/category/music.htm";
                flag = 0;
                flag = messageService.insert(url,encoding,EntityConsist.MessageConsist.MUSIC);
                url = "https://www.cnbeta.com/category/game.htm";
                flag =0 ;
                flag = messageService.insert(url,encoding,EntityConsist.MessageConsist.GAME);
                url ="https://www.cnbeta.com/category/funny.htm";
                flag = 0;
                flag = messageService.insert(url,encoding,EntityConsist.MessageConsist.FUNNY);
                url ="https://www.cnbeta.com/category/soft.htm";
                flag = 0;
                flag = messageService.insert(url,encoding,EntityConsist.MessageConsist.SOFT);
            if(flag == 0 ){
                return "发生异常";
            }else {
                return "hellow";
            }
        }
        @RequestMapping("/getMessageJson")
        @ResponseBody
        public String getMessageJson(MessageEntity messageEntity){
            List<MessageEntity> messageEntities = messageService.queryMessageByTypeValue(messageEntity);
            Gson gson = new Gson();
            String json = gson.toJson(messageEntities);
            return  json;
        }
}
